package heliotrope.res
{
	import flash.utils.Dictionary;
	
	import heliotrope.global.ErrorHandler;
	import heliotrope.utils.collection.HashSet;

	public class TileSets
	{
		private var _sets:Dictionary;
		public function TileSets(settings_:Vector.<TileSetting>)
		{
			_sets = new Dictionary;
			init(settings_);
		}
		
		private function init(settings_:Vector.<TileSetting>):void
		{
			for each (var set:TileSetting in settings_)
			{
				var id:uint = set.id;
				CONFIG::debug
				{
					try
					{
						if(_sets[id]) throw new DefinitionError("Duplicate tileset id.");
					} 
					catch(error:DefinitionError) 
					{
						ErrorHandler.handle(error);
					}
				}
				_sets[id] = new TileResource(id, set.numX, set.numY);
			}
		}
		
		public function getRes(id_:uint):TileResource
		{
			CONFIG::debug
			{
				try
				{
					if(!_sets[id_]) throw new DefinitionError("No such id of TileResource.");
				} 
				catch(error:DefinitionError) 
				{
					ErrorHandler.handle(error);
				}
			}
			return _sets[id_];
		}
	}
}